package rubik.crossover;

import rubik.CubeSolution;
import rubik.ICubeSolution;

public class RandomMargeCrossOver extends AbstractCrossOver{

	@Override
	public ICubeSolution applyCrossOver(ICubeSolution firstParent,
			ICubeSolution secondParent) {

			int r1 = r.nextInt(firstParent.getSeqs().size());
			int r2 = r.nextInt(secondParent.getSeqs().size());
			CubeSolution newSeq = new CubeSolution(firstParent.getCube(), firstParent.getSeqGenerator(), firstParent.getMutator(), firstParent.getFitnessFunc(), firstParent.getCrossoverFunc());
			for (int i = 0; i < r1; i++) {
				newSeq.getSeqs().add(firstParent.getSeqs().get(i));
			}
			for (int i = r2; i < secondParent.getSeqs().size(); i++) {
				newSeq.getSeqs().add(secondParent.getSeqs().get(i));
			}
		return newSeq;
	}

}
